"use strict";
cc._RF.push(module, 'e2061ax6XNHr7Ago7iiqAoa', 'PipeManager');
// script/PipeManager.js

"use strict";

var PipeGroup = require('PipeGroup');

cc.Class({
  "extends": cc.Component,
  properties: {
    //管道节点预置资源
    pipePrefab: cc.Prefab,
    //管道移动速度
    pipeMoveSpeed: -300,
    //每对管道之间的距离
    pipeSpacing: 400
  },
  // LIFE-CYCLE CALLBACKS:
  // onLoad () {},
  onLoad: function onLoad() {
    this.pipeList = [];
    this.isRunning = false;
  },
  start: function start() {},
  startSpawn: function startSpawn() {
    this.spawnPipe();
    var spawnInterval = Math.abs(this.pipeSpacing / this.pipeMoveSpeed);
    this.schedule(this.spawnPipe, spawnInterval);
    this.isRunning = true;
  },
  spawnPipe: function spawnPipe() {
    var pipeGroup = null;

    if (cc.pool.hasObject(PipeGroup)) {
      pipeGroup = cc.pool.getFromPool(PipeGroup);
    } else {
      pipeGroup = cc.instantiate(this.pipePrefab).getComponent(PipeGroup);
    }

    this.node.addChild(pipeGroup.node);
    pipeGroup.node.active = true;
    pipeGroup.init(this);
    this.pipeList.push(pipeGroup);
  },
  recyclePipe: function recyclePipe(pipe) {
    pipe.node.removeFromParent();
    pipe.node.active = false;
    cc.pool.putInPool(pipe);
  },
  getNext: function getNext() {
    return this.pipeList.shift();
  },
  reset: function reset() {
    this.unschedule(this.spawnPipe);
    this.pipeList = [];
    this.isRunning = false;
  } // update (dt) {},

});

cc._RF.pop();